﻿namespace MyWebapiDemo.Handler
{
    /// <summary>
    /// 提供基础方法
    /// </summary>
    /// 创建时间：2023-4-13 09:21:49。作者：王浩力
    public class RootHandler
    {
        /// <summary>
        /// 判断是否为ajax请求
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static bool IsAjax(HttpRequest req)
        {
            //X-Requested-With: XMLHttpRequest
            bool result = false;
            var xreq = req.Headers.ContainsKey("x-requested-with");
            if (xreq)
            {
                result = req.Headers["x-requested-with"] == "XMLHttpRequest";
            }
            return result;
        }


    }
}
